<?php
/**
 * A basic debugging helper.
 */
class Debug {
    /**
     * Display.
     * @param mixed $data
     */
    static public function display($data, $exit = false) {
        if(!Framework::getConfig()->getSection('general')->debug) {
            return;
        }
        echo "<pre>";
        print_r($data);
        echo "</pre>";
        if($exit) {
            exit;
        }
    }

    /**
     * Dump.
     * @param mixed $data
     */
    static public function dump($data, $exit = false) {
        if(!Framework::getConfig()->getSection('general')->debug) {
            return;
        }
        echo "<pre>";
        var_dump($data);
        echo "</pre>";
        if($exit) {
            exit;
        }
    }

    /**
     * Show details of an exception.
     * @param Exception $e
     */
	static public function showException(Exception $e) {
        if(!Framework::getConfig()->getSection('general')->debug) {
            return;
        }
        $class = ucwords(str_replace('_', ' ', get_class($e)));
        $msg = $e->getMessage();
        $trace = $e->getTraceAsString();
        echo <<<HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
body { font-family: Deja Vu Sans, Verdana, Helvetica, Ariel, sans-serif; font-size: small; }
#header { background-color: #F3ECB2; padding: 2px; border: 1px solid #BAAD8B; margin-bottom: 4px; }
#trace { border: 1px solid #BAAD8B; }
</style>
<title>$class</title>
</head>
<body>
<div id="header">
<h1>$class</h1>
<p>$msg</p>
</div>
<div id="trace">
<strong>Trace:</strong>
<pre>$trace</pre>
</div>
</body>
</html>
HTML;
	}
}
?>
